home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 335_02 / as6805.y < prev    next >
Text File  |  1990-12-02  |  37KB  |  1,656 lines

  1. %{
  2.  
  3. /*
  4. HEADER:     ;
  5. TITLE:         Frankenstein Cross Assemblers;
  6. VERSION:     2.0;
  7. DESCRIPTION: "    Reconfigurable Cross-assembler producing Intel (TM)
  8.         Hex format object records.  ";
  9. KEYWORDS:     cross-assemblers, 1805, 2650, 6301, 6502, 6805, 6809, 
  10.         6811, tms7000, 8048, 8051, 8096, z8, z80;
  11. SYSTEM:     UNIX, MS-Dos ;
  12. FILENAME:     as6805.y;
  13. WARNINGS:     "This software is in the public domain.  
  14.         Any prior copyright claims are relinquished.  
  15.  
  16.         This software is distributed with no warranty whatever.  
  17.         The author takes no responsibility for the consequences 
  18.         of its use.
  19.  
  20.         Yacc (or Bison) required to compile."  ;
  21. SEE-ALSO:     as6805.doc,frasmain.c;    
  22. AUTHORS:     Mark Zenier;
  23. COMPILERS:     Microport Sys V/AT, ATT Yacc, Turbo C V1.5, Bison (CUG disk 285)
  24.         (previous versions Xenix, Unisoft 68000 Version 7, Sun 3);
  25. */
  26. /* 6805 instruction generation file */
  27. /* November 17, 1990 */
  28.  
  29. /*
  30.     description    frame work parser description for framework cross
  31.             assemblers
  32.     history        February 2, 1988
  33.             September 11, 1990 - merge table definition
  34.             September 12, 1990 - short file names
  35.             September 14, 1990 - short variable names
  36.             September 17, 1990 - use yylex as external
  37. */
  38. #include <stdio.h>
  39. #include "frasmdat.h"
  40. #include "fragcon.h"
  41.  
  42. #define yylex lexintercept
  43.  
  44. /*
  45.     file        fraselcrit.h
  46.     author        Mark Zenier
  47.     description    Selection criteria and token values for 6805
  48.             framework assembler
  49.     usage        framework cross assembler
  50.     history        September 19, 1987
  51.             October 2, 1987
  52.             June 7, 1989  fix relative addressing (BRset/clr)
  53. */
  54.     /* selectors for the ST_EXP address */
  55.     /* 0000 0000 0000 00xx */
  56. #define ADDR        0x3
  57. #define DIRECT        0x1
  58. #define EXTENDED    0x2
  59.  
  60.     /* selectors for the ST_IND offset */
  61.     /* 0000 0000 000x xx00 */
  62. #define INDEXLEN    0x1C
  63. #define INDEX0        0x4
  64. #define INDEX1        0x8
  65. #define INDEX2        0x10
  66.  
  67.     /* selectors for instruction set extensions */
  68.     /* 0000 0000 xxx0 0000 */
  69. #define INSTSTWA    0x20
  70. #define INSTMUL    0x40
  71. #define INSTDAA    0x80
  72.  
  73.     /* cpu instruction extensions */
  74. #define CPU6805    0
  75. #define CPU146805    INSTSTWA
  76. #define CPU68HC05    (INSTSTWA | INSTMUL)
  77. #define CPU6305    (INSTSTWA | INSTDAA)
  78. #define ST_BRSET 0x1
  79. #define ST_BSET 0x2
  80. #define ST_EXP 0x4
  81. #define ST_IMM 0x8
  82. #define ST_IND 0x10
  83. #define ST_INH 0x20
  84.     
  85.     int    cpuselect = CPU6805;
  86.     static char    genbdef[] = "[1=];";
  87.     static char    genwdef[] = "[1=]x";
  88.     char ignosyn[] = "[Xinvalid syntax for instruction";
  89.     char ignosel[] = "[Xinvalid operands/illegal instruction for cpu";
  90.  
  91.     long    labelloc;
  92.     static int satsub;
  93.     int    ifstkpt = 0;
  94.     int    fraifskip = FALSE;
  95.  
  96.     struct symel * endsymbol = SYMNULL;
  97.  
  98. %}
  99. %union {
  100.     int    intv;
  101.     long     longv;
  102.     char    *strng;
  103.     struct symel *symb;
  104.     struct {int indexv, ex; } inetre;
  105. }
  106.  
  107. %token <intv> INDEX
  108. %type <inetre> indexed
  109. %token <intv> KOC_BDEF
  110. %token <intv> KOC_ELSE
  111. %token <intv> KOC_END
  112. %token <intv> KOC_ENDI
  113. %token <intv> KOC_EQU
  114. %token <intv> KOC_IF
  115. %token <intv> KOC_INCLUDE
  116. %token <intv> KOC_ORG
  117. %token <intv> KOC_RESM
  118. %token <intv> KOC_SDEF
  119. %token <intv> KOC_SET
  120. %token <intv> KOC_WDEF
  121. %token <intv> KOC_CHSET
  122. %token <intv> KOC_CHDEF
  123. %token <intv> KOC_CHUSE
  124. %token <intv> KOC_CPU
  125. %token <intv> KOC_opcode
  126.  
  127. %token <longv> CONSTANT
  128. %token EOL
  129. %token KEOP_AND
  130. %token KEOP_DEFINED
  131. %token KEOP_EQ
  132. %token KEOP_GE
  133. %token KEOP_GT
  134. %token KEOP_HIGH
  135. %token KEOP_LE
  136. %token KEOP_LOW
  137. %token KEOP_LT
  138. %token KEOP_MOD
  139. %token KEOP_MUN
  140. %token KEOP_NE
  141. %token KEOP_NOT
  142. %token KEOP_OR
  143. %token KEOP_SHL
  144. %token KEOP_SHR
  145. %token KEOP_XOR
  146. %token KEOP_locctr
  147. %token <symb> LABEL
  148. %token <strng> STRING
  149. %token <symb> SYMBOL
  150.  
  151. %token KTK_invalid
  152.  
  153. %right    KEOP_HIGH KEOP_LOW
  154. %left    KEOP_OR KEOP_XOR
  155. %left    KEOP_AND
  156. %right    KEOP_NOT
  157. %nonassoc    KEOP_GT KEOP_GE KEOP_LE KEOP_LT KEOP_NE KEOP_EQ
  158. %left    '+' '-'
  159. %left    '*' '/' KEOP_MOD KEOP_SHL KEOP_SHR
  160. %right    KEOP_MUN
  161.  
  162.  
  163. %type <intv> expr exprlist stringlist
  164.  
  165. %start file
  166.  
  167. %%
  168.  
  169. file    :    file allline
  170.     |    allline
  171.     ;
  172.  
  173. allline    :     line EOL
  174.             {
  175.                 clrexpr();
  176.             }
  177.     |    EOL
  178.     |    error EOL
  179.             {
  180.                 clrexpr();
  181.                 yyerrok;
  182.             }
  183.     ;
  184.  
  185. line    :    LABEL KOC_END 
  186.             {
  187.                 endsymbol = $1;
  188.                 nextreadact = Nra_end;
  189.             }
  190.     |          KOC_END 
  191.             {
  192.                 nextreadact = Nra_end;
  193.             }
  194.     |    KOC_INCLUDE STRING
  195.             {
  196.         if(nextfstk >= FILESTKDPTH)
  197.         {
  198.             fraerror("include file nesting limit exceeded");
  199.         }
  200.         else
  201.         {
  202.             infilestk[nextfstk].fnm = savestring($2,strlen($2));
  203.             if( (infilestk[nextfstk].fpt = fopen($2,"r"))
  204.                 ==(FILE *)NULL )
  205.             {
  206.                 fraerror("cannot open include file");
  207.             }
  208.             else
  209.             {
  210.                 nextreadact = Nra_new;
  211.             }
  212.         }
  213.             }
  214.     |    LABEL KOC_EQU expr 
  215.             {
  216.                 if($1 -> seg == SSG_UNDEF)
  217.                 {
  218.                     pevalexpr(0, $3);
  219.                     if(evalr[0].seg == SSG_ABS)
  220.                     {
  221.                         $1 -> seg = SSG_EQU;
  222.                         $1 -> value = evalr[0].value;
  223.                         prtequvalue("C: 0x%lx\n",
  224.                             evalr[0].value);
  225.                     }
  226.                     else
  227.                     {
  228.                         fraerror(
  229.                     "noncomputable expression for EQU");
  230.                     }
  231.                 }
  232.                 else
  233.                 {
  234.                     fraerror(
  235.                 "cannot change symbol value with EQU");
  236.                 }
  237.             }
  238.     |    LABEL KOC_SET expr 
  239.             {
  240.                 if($1 -> seg == SSG_UNDEF
  241.                    || $1 -> seg == SSG_SET)
  242.                 {
  243.                     pevalexpr(0, $3);
  244.                     if(evalr[0].seg == SSG_ABS)
  245.                     {
  246.                         $1 -> seg = SSG_SET;
  247.                         $1 -> value = evalr[0].value;
  248.                         prtequvalue("C: 0x%lx\n",
  249.                             evalr[0].value);
  250.                     }
  251.                     else
  252.                     {
  253.                         fraerror(
  254.                     "noncomputable expression for SET");
  255.                     }
  256.                 }
  257.                 else
  258.                 {
  259.                     fraerror(
  260.                 "cannot change symbol value with SET");
  261.                 }
  262.             }
  263.     |    KOC_IF expr 
  264.             {
  265.         if((++ifstkpt) < IFSTKDEPTH)
  266.         {
  267.             pevalexpr(0, $2);
  268.             if(evalr[0].seg == SSG_ABS)
  269.             {
  270.                 if(evalr[0].value != 0)
  271.                 {
  272.                     elseifstk[ifstkpt] = If_Skip;
  273.                     endifstk[ifstkpt] = If_Active;
  274.                 }
  275.                 else
  276.                 {
  277.                     fraifskip = TRUE;
  278.                     elseifstk[ifstkpt] = If_Active;
  279.                     endifstk[ifstkpt] = If_Active;
  280.                 }
  281.             }
  282.             else
  283.             {
  284.                 fraifskip = TRUE;
  285.                 elseifstk[ifstkpt] = If_Active;
  286.                 endifstk[ifstkpt] = If_Active;
  287.             }
  288.         }
  289.         else
  290.         {
  291.             fraerror("IF stack overflow");
  292.         }
  293.             }
  294.                         
  295.     |    KOC_IF 
  296.             {
  297.         if(fraifskip) 
  298.         {
  299.             if((++ifstkpt) < IFSTKDEPTH)
  300.             {
  301.                     elseifstk[ifstkpt] = If_Skip;
  302.                     endifstk[ifstkpt] = If_Skip;
  303.             }
  304.             else
  305.             {
  306.                 fraerror("IF stack overflow");
  307.             }
  308.         }
  309.         else
  310.         {
  311.             yyerror("syntax error");
  312.             YYERROR;
  313.         }
  314.                 }
  315.                         
  316.     |    KOC_ELSE 
  317.             {
  318.                 switch(elseifstk[ifstkpt])
  319.                 {
  320.                 case If_Active:
  321.                     fraifskip = FALSE;
  322.                     break;
  323.                 
  324.                 case If_Skip:
  325.                     fraifskip = TRUE;
  326.                     break;
  327.                 
  328.                 case If_Err:
  329.                     fraerror("ELSE with no matching if");
  330.                     break;
  331.                 }
  332.             }
  333.  
  334.     |    KOC_ENDI 
  335.             {
  336.                 switch(endifstk[ifstkpt])
  337.                 {
  338.                 case If_Active:
  339.                     fraifskip = FALSE;
  340.                     ifstkpt--;
  341.                     break;
  342.                 
  343.                 case If_Skip:
  344.                     fraifskip = TRUE;
  345.                     ifstkpt--;
  346.                     break;
  347.                 
  348.                 case If_Err:
  349.                     fraerror("ENDI with no matching if");
  350.                     break;
  351.                 }
  352.             }
  353.     |    LABEL KOC_ORG expr 
  354.             {
  355.                 pevalexpr(0, $3);
  356.                 if(evalr[0].seg == SSG_ABS)
  357.                 {
  358.                     locctr = labelloc = evalr[0].value;
  359.                     if($1 -> seg == SSG_UNDEF)
  360.                     {
  361.                         $1 -> seg = SSG_ABS;
  362.                         $1 -> value = labelloc;
  363.                     }
  364.                     else
  365.                         fraerror(
  366.                         "multiple definition of label");
  367.                     prtequvalue("C: 0x%lx\n",
  368.                         evalr[0].value);
  369.                 }
  370.                 else
  371.                 {
  372.                     fraerror(
  373.                      "noncomputable expression for ORG");
  374.                 }
  375.             }
  376.     |          KOC_ORG expr 
  377.             {
  378.                 pevalexpr(0, $2);
  379.                 if(evalr[0].seg == SSG_ABS)
  380.                 {
  381.                     locctr = labelloc = evalr[0].value;
  382.                     prtequvalue("C: 0x%lx\n",
  383.                         evalr[0].value);
  384.                 }
  385.                 else
  386.                 {
  387.                     fraerror(
  388.                      "noncomputable expression for ORG");
  389.                 }
  390.             }
  391.     |    LABEL KOC_CHSET
  392.             {
  393.                 if($1 -> seg == SSG_UNDEF)
  394.                 {
  395.                     $1 -> seg = SSG_EQU;
  396.                     if( ($1->value = chtcreate()) <= 0)
  397.                     {
  398.         fraerror( "cannot create character translation table");
  399.                     }
  400.                     prtequvalue("C: 0x%lx\n", $1 -> value);
  401.                 }
  402.                 else
  403.                 {
  404.             fraerror( "multiple definition of label");
  405.                 }
  406.             }
  407.     |        KOC_CHUSE
  408.             {
  409.                 chtcpoint = (int *) NULL;
  410.                 prtequvalue("C: 0x%lx\n", 0L);
  411.             }
  412.     |        KOC_CHUSE expr
  413.             {
  414.                 p